﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ThreadFramework
{
    public class TimerThead
    {
        private Thread thTime;
        private YLTime ylInstance = new YLTime();

        public void InitSingal(EventHandler handler) 
        {            
            ylInstance.EvtOnTimeDone += handler;
        }

        public void Start(int time)
        {
            ParameterizedThreadStart pts = new ParameterizedThreadStart(ylInstance.Init);
            thTime = new Thread(pts);
            thTime.IsBackground = true;
            thTime.Name = "timerThread";
            thTime.Start(time);
        }

        public void Inrupt()
        {
            ylInstance.SendOpenSingal();
        }

        public void Run() 
        {
            ylInstance.StartTimer();
        }

        public void Terminate()
        {
            if (thTime != null)
            {
                thTime.Abort();
                thTime.Join();
            }
        }
    }
}
